<template>
  <!-- 入党申请详情 -->
  <el-dialog class="detail_dialog"
  :visible.sync="visible" 
  title="查看发展详情" 
  @close="cancel"
  :close-on-click-modal="false" 
  :close-on-press-escape="false"
  :append-to-body="true"
  style="overflow: hidden;"
  >
  <!-- <el-button type="primary" style="margin-bottom:6vh;" @click="additional(stert,userid,applicationIds)">补充资料</el-button> -->
  <el-row v-if="showinfo" class="detail_row">
      <el-col :span="12">
          <el-form class="detail_form1">
            <el-form-item v-if="stert=='团员'" label="入党申请书："><span class="downLook" @click="lookdown('shenqing')">点击下载查看</span></el-form-item>
            <!-- <el-form-item v-if="stert=='入党积极分子'" label="会议记录："><span class="downLook" @click="lookdown">点击下载查看</span></el-form-item> -->
            <el-form-item label="申请人：">{{username}}</el-form-item>
            <el-form-item label="开始时间：">{{memberdetail.startTime}}</el-form-item>
            <el-form-item label="当前入党阶段：">{{memberdetail.start}}</el-form-item>
            <el-form-item v-if="stert=='发展对象'" label="会议名称：">{{memberdetail.conferenceDecideVo.name}}</el-form-item>
            <el-form-item v-if="stert=='发展对象'" label="会议人数：">{{memberdetail.conferenceDecideVo.count}}</el-form-item>
            <el-form-item v-if="stert=='入党积极分子'" label="党课培训合格证书："><span class="downLook" @click="lookdown('hege')">点击下载查看</span></el-form-item>
            <el-form-item v-if="stert=='发展对象'" label="赞成人数：">{{memberdetail.conferenceDecideVo.approveNumber}}</el-form-item>
            <el-form-item v-if="stert=='发展对象'" label="反对人数：">{{memberdetail.conferenceDecideVo.opposeNumber}}</el-form-item>
            <el-form-item v-if="stert=='发展对象'" label="赞成人数所占百分比：">{{memberdetail.conferenceDecideVo.percent}}</el-form-item>
            <el-form-item v-if="stert=='发展对象'" label="决议是否通过：">{{memberdetail.conferenceDecideVo.isAgreement}}</el-form-item>
        </el-form>
      </el-col>
      <el-col :span="12">
          <el-form label-position="right" label-width="130px" class="detail_form2">
            <el-form-item label="是否同意：">{{memberdetail.isAgreement}}</el-form-item>
            <el-form-item label="结束时间：">{{memberdetail.endTime}}</el-form-item>
            <el-form-item label="申请成为：">{{memberdetail.end}}</el-form-item>
            <el-form-item v-if="stert=='团员'" label="团员推优人：">{{memberdetail.referrerName}}</el-form-item>
            <el-form-item v-if="stert=='入党积极分子'" label="入党介绍人：">{{memberdetail.introducerOneName}}、{{memberdetail.introducerTwoName}}</el-form-item>
            <el-form-item v-if="stert=='团员'" label="会议附件：">
                <span @click="lookdown('metting')" class="downLook">点击下载查看</span>
            </el-form-item>
            <el-form-item v-if="stert=='发展对象'" label="会议时间：">{{memberdetail.conferenceDecideVo.time}}</el-form-item>
            <el-form-item v-if="stert=='发展对象'" label="培养人意见：">{{memberdetail.cultivateOpinion}}</el-form-item>
            <el-form-item v-if="stert=='发展对象'" label="党和群众意见：">{{memberdetail.partyMessesOpinion}}</el-form-item>
            <el-form-item v-if="stert=='发展对象'" label="入党志愿书："><span class="downLook" @click="lookdown('partyApplicationAttachment')">点击下载查看</span></el-form-item>
            <el-form-item v-if="stert=='发展对象'" label="品德证明："><span class="downLook" @click="lookdown('referenceCheck')">点击下载查看</span></el-form-item>
        </el-form>
      </el-col>
  </el-row>
  <el-form v-else>
      <el-form-item label="延期原因:">
        <el-input class="saveConferenceDtoTextarea" type="textarea"
        placeholder="请输入内容"
        :rows="5"
        v-model="reason"
        show-word-limit></el-input>
      </el-form-item>
      <el-form-item label="最终延期时间:">
        <div class="block">
            <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="extensionTime"
            type="datetime"
            placeholder="选择日期">
            </el-date-picker>
        </div>
    </el-form-item>
  </el-form>
  <div v-if="showinfo" class="detail_btn">
      <el-button class="agree" type="primary" @click="agree" :disabled="able">同意申请</el-button>
      <el-button type="danger" @click="reject" :disabled="able">驳回申请</el-button>
      <el-button v-if="stert=='预备党员'" type="warning" @click="extension" :disabled="able">延期转正</el-button>
  </div>
  <div v-else class="detail_btn">
      <el-button type="primary" @click="subextension">提交</el-button>
      <el-button @click="recover" type="warning">返回</el-button>
  </div>
  </el-dialog>
</template>

<script>
export default {
    data(){
        return{
            visible:false,
            memberdetail:{
                conferenceDecideVo:{
                    approveNumber:"",
                    count:"",
                    isAgreement:"",
                    name:"",
                    opposeNumber:"",
                    percent:"",
                    time:"",
                    waiverNumber:"",
                },
                url:"",//下载用户上传的入党申请书
                start:"",//申请人当前发展阶段
                end:"",//申请成为
                startTime:"",//开始时间
                endTime:"",//结束时间
                isAgreement:"",//是否同意：0:未同意；1：已同意
                attachment:"",//会议附件
                referrerName:"",//会议人
            },
            username:"",//提交申请的用户名
            stert:"",//申请人当前发展阶段
            userid:"",//申请人id
            applicationId:"",//申请流程id
            showinfo:true,//显示入党信息
            reason:"",//延期原因
            extensionTime:"",//最终延期时间
            able:false,//是否禁用
        }
    },
    mounted(){},
    methods:{
        init (start,userid,id) {
            this.stert = start
            this.userid = userid
            this.applicationId = id
            this.visible = true
            this.$nextTick(() => {
            })
            // console.log(start,userid,id)
            // console.log(this.memberdetail)
            this.axios({
                headers:{'Authentication':localStorage.getItem('token')},
                method:"get",
                // url:`api/application/getAdminApplicationList`,
                url:`/application/getAdminApplicationList?userId=${userid}`,
            }).then(res=>{
                if(res.data.code != 20001){
                    return this.$message.error(res.data.msg)
                }
                // console.log(res.data.data.list)
                if(res.data.data.list.length>0){
                    this.username = res.data.data.list[0].userName
                }
            })
            if(start=="团员"){//调用查询团员申请完整信息接口
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"get",
                    url:`/application/getMemberApplicationDetail?applicationId=${id}`,
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    // console.log(res.data.data)
                    this.memberdetail = res.data.data
                    // console.log(this.memberdetail.endTime)
                    if(this.memberdetail.isAgreement==0){
                        this.memberdetail.isAgreement = "未同意"
                    }else{
                        this.memberdetail.isAgreement = "已同意"
                    }
                    if(this.memberdetail.endTime!=null){
                        this.able = true
                    }
                })
            }else if(start=="入党积极分子"){
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"get",
                    url:`/application/getActivityApplicationDetail?applicationId=${id}`,
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    // console.log(res.data.data)
                    this.memberdetail = res.data.data
                    if(this.memberdetail.isAgreement==0){
                        this.memberdetail.isAgreement = "未同意"
                    }else{
                        this.memberdetail.isAgreement = "已同意"
                    }
                    if(this.memberdetail.endTime!=null){
                        this.able = true
                    }
                })
            }else if(start=="发展对象"){
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"get",
                    url:`/application/getDevelopApplicationDetail?applicationId=${id}`,
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    // console.log(res.data.data)
                    this.memberdetail = res.data.data
                    if(this.memberdetail.isAgreement==0){
                        this.memberdetail.isAgreement = "未同意"
                    }else{
                        this.memberdetail.isAgreement = "已同意"
                    }
                    if(this.memberdetail.endTime!=null){
                        this.able = true
                    }
                    if(this.memberdetail.conferenceDecideVo.isAgreement==0){
                        this.memberdetail.conferenceDecideVo.isAgreement = "未通过"
                    }else{
                        this.memberdetail.conferenceDecideVo.isAgreement = "已通过"
                    }
                    this.memberdetail.conferenceDecideVo.percent = this.memberdetail.conferenceDecideVo.percent*100+"%"
                    // console.log(this.memberdetail)
                })
            }else if(start=="预备党员"){
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"get",
                    url:`/application/getReadyApplicationDetail?applicationId=${id}`,
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    // console.log(res.data.data)
                    this.memberdetail = res.data.data
                    // console.log(this.memberdetail.endTime)
                    if(this.memberdetail.isAgreement==0){
                        this.memberdetail.isAgreement = "未同意"
                    }else{
                        this.memberdetail.isAgreement = "已同意"
                    }
                    if(this.memberdetail.endTime!=null){
                        this.able = true
                    }
                })
            }
            // console.log(this.memberdetail)
        },
        cancel(){
            this.visible = false
            this.able = false
        },
        lookdown(e){//点击查看入党申请材料
            // console.log(this.memberdetail)
            if(e=="shenqing" ){//入党申请书
                if(this.memberdetail.applyForm!=null){
                    window.location.href = this.memberdetail.applyForm
                }else{
                    this.$message({
                        message: '用户还未上传入党申请书！',
                        type: 'warning'
                    });
                }
            }else if(e=="hege"){//党课合格培训证书
                if(this.memberdetail.trainRecord!=null){
                    window.location.href = this.memberdetail.trainRecord
                }else{
                    this.$message({
                        message: '未上传党课合格培训证书！',
                        type: 'warning'
                    });
                }  
            }else if(e=="metting"){//查看会议附件
                if(this.memberdetail.attachment!=null){
                    window.location.href = this.memberdetail.attachment
                }else{
                    this.$message({
                        message: '还未添加会议附件！',
                        type: 'warning'
                    });
                }
            }
            else if(e=="partyApplicationAttachment"){//查看入党志愿书
                if(this.memberdetail.partyApplicationAttachment!=null){
                    window.location.href = this.memberdetail.partyApplicationAttachment
                }
               else{
                   this.$message({
                        message: '还未上传入党志愿书！',
                        type: 'warning'
                    });
               } 
            }else if(e=="referenceCheck"){//查看品德证明
                if(this.memberdetail.referenceCheck!=null){
                    window.location.href = this.memberdetail.referenceCheck
                }else{
                    this.$message({
                        message: '还未上传品德证明！',
                        type: 'warning'
                    });
                }
                
            }
        },
        agree(){//点击同意申请
            if(this.stert=="团员"){
                var pre = new FormData()
                pre.append("userId",this.userid)
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"post",
                    // url:`api/application/getAdminApplicationList`,
                    url:`/application/memberApplicationAgreement`,
                    data:pre
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    this.$alert('已同意申请!',{
                        confirmButtonText:'确定',
                        callback:action=>{
                            this.visible = false
                           this.$emit('flow')
                        }
                    })
                })
            }
            if(this.stert=="入党积极分子"){
                var pre = new FormData()
                pre.append("userId",this.userid)
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"post",
                    // url:`api/application/getAdminApplicationList`,
                    url:`/application/activityApplicationAgreement`,
                    data:pre
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    this.$alert('已同意申请!',{
                        confirmButtonText:'确定',
                        callback:action=>{
                            this.visible = false
                           this.$emit('flow')
                        }
                    })
                })
            }
            if(this.stert=="发展对象"){
                var pre = new FormData()
                pre.append("userId",this.userid)
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"post",
                    url:`/application/developApplicationAgreement`,
                    data:pre,
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    this.$alert('已同意申请!',{
                        confirmButtonText:'确定',
                        callback:action=>{
                            this.visible = false
                           this.$emit('flow')
                        }
                    })
                })
            }
            if(this.stert=="预备党员"){
                var pre = new FormData()
                pre.append("userId",this.userid)
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"post",
                    url:`/application/readyApplicationAgreement`,
                    data:pre,
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    this.$alert('已同意申请!',{
                        confirmButtonText:'确定',
                        callback:action=>{
                            this.visible = false
                           this.$emit('flow')
                        }
                    })
                })
            }
        },
        extension(){//点击延期转正按钮
            this.showinfo = false
        },
        subextension(){//点击提交延期转正信息
            this.axios({
                headers:{'Authentication':localStorage.getItem('token')},
                method:"post",
                url:`/application/postpone`,
                data:{
                    cause:this.reason,
                    duration:this.extensionTime,
                    userId:this.userid
                }
            }).then(res=>{
                if(res.data.code != 20001){
                    return this.$message.error(res.data.msg)
                }
                this.$alert('提交成功!',{
                    confirmButtonText:'确定',
                    callback:action=>{
                        this.visible = false
                        this.$emit('flow')
                    }
                })
            })
        },
        recover(){//点击返回按钮
            this.showinfo = true
        },
        reject(){//驳回申请
            var pre = new FormData()
            pre.append("userId",this.userid)
            if(this.stert=="团员"){
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"post",
                    url:`/application/memberApplicationDisagreement`, 
                    data:pre
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    this.$alert('已驳回申请!',{
                        confirmButtonText:'确定',
                        callback:action=>{
                            this.visible = false
                            this.$emit('flow')
                        }
                    })
                })
            }
            if(this.stert=="入党积极分子"){
                var appId = new FormData()
                appId.append("applicationId",this.applicationId)
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"post",
                    url:`/application/activityApplicationDisagreement`, 
                    data:appId
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    this.$alert('已驳回申请!',{
                        confirmButtonText:'确定',
                        callback:action=>{
                            this.visible = false
                            this.$emit('flow')
                        }
                    })
                })
            }
            if(this.stert=="发展对象"){
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"post",
                    url:`/application/developApplicationDisAgreement`, 
                    data:pre
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    this.$alert('已驳回申请!',{
                        confirmButtonText:'确定',
                        callback:action=>{
                            this.visible = false
                            this.$emit('flow')
                        }
                    })
                })
            }
            if(this.stert=="预备党员"){
                this.axios({
                    headers:{'Authentication':localStorage.getItem('token')},
                    method:"post",
                    url:`/application/readyApplicationDisagreement`, 
                    data:pre
                }).then(res=>{
                    if(res.data.code != 20001){
                        return this.$message.error(res.data.msg)
                    }
                    this.$alert('已驳回申请!',{
                        confirmButtonText:'确定',
                        callback:action=>{
                            this.visible = false
                            this.$emit('flow')
                        }
                    })
                })
            }
        }
    }
}
</script>

<style lang="scss">
    .detail_dialog{
        .downLook{
            cursor: pointer;
            color: #f00;
        }
        .downLook:hover{
            color: royalblue;
        }
        .el-dialog{
            height: 78vh;
        }
        .detail_form1{
            // border: 1px solid #000;
            margin-left: 5vw;
        }
        .detail_form2{
            // border: 1px solid #f00;
        }
        .detail_btn{
            position: absolute;
            left: 0;
            bottom: 3vh;
            width: 100%;
            text-align: center;
        }
        .detail_row{
            height: 54vh;
            overflow: auto;
            // border: 1px solid #000;
        }
        .saveConferenceDtoTextarea{
            width: 35vw;
        }
    }
</style>